home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / mm_tease.zip / SOURCE.LZH / VGA4PAGE.PAS < prev   
Pascal/Delphi Source File  |  1992-12-12  |  3KB  |  111 lines

  1. Unit VGA4Page;
  2.  
  3. interface
  4.  
  5. Procedure Screen(page:byte);
  6. Procedure SetMode13x4;
  7. Procedure PutPixel(x,y:integer;color,page:byte);
  8. Function  GetPixel(x,y:integer;page:byte):byte;
  9. Procedure HLine(x1,x2,y:integer;color,page:byte);
  10. Procedure ClearScreen (page:byte);
  11. Procedure CopyPage(page1,page2:byte);
  12.  
  13. implementation
  14.  
  15. const
  16.   StartIndex=0;
  17.   EndIndex=StartIndex+3;
  18.   Offset_Adr:Array[StartIndex..EndIndex] OF WORD=($0000,$3E80,$7D00,$BB80);
  19.   Segment_Adr:ARRAY[StartIndex..EndIndex] OF WORD=($A000,$A3E8,$A7D0,$ABB8);
  20.  
  21. Procedure Screen(page:byte);
  22. begin
  23.   while (port[$3da] and 8)<>8 do;
  24.   while (port[$3da] and 8)=8 do;
  25.   port[$3D4]:=$0D;
  26.   port[$3D5]:=lo(offset_adr[page]);
  27.   port[$3D4]:=$0C;
  28.   port[$3D5]:=hi(offset_adr[page]);
  29. end;
  30.  
  31. Procedure SetMode13x4;
  32. begin
  33.   inline($b8/$13/$00/$cd/$10); { mov ax,0013h / int 10h }
  34.   port[$3C4]:=4;
  35.   port[$3C5]:=port[$3C5] AND $F7 OR $04;
  36.   port[$3C4]:=2;
  37.   port[$3C5]:=$0F;
  38.   fillchar(mem[$A000:$0000],$FFFF,0);
  39.   port[$3D4]:=$14;
  40.   port[$3D5]:=port[$3D5] AND $BF;
  41.   port[$3D4]:=$17;
  42.   port[$3D5]:=port[$3D5] OR $40;
  43.   screen(0);
  44. end;
  45.  
  46. Procedure PutPixel(x,y:integer;color,page:byte);
  47. begin
  48.   if (x<0) or (x>319) or (y<0) or (y>199) then
  49.     exit;
  50.   portw[$3C4]:=$0002 or ((1 shl (x and 3)) shl 8);
  51.   mem[segment_adr[page]:$50*y+x shr 2]:=color;
  52. end;
  53.  
  54. Function GetPixel(x,y:integer; page:byte):byte;
  55. begin
  56.   portw[$3CE]:=$0004 OR ((x mod 4) shl 8);
  57.   GetPixel:=mem[Segment_Adr[page]:x shr 2 + y*$50];
  58. end;
  59.  
  60. Procedure HLine(x1,x2,y:integer;color,page:byte);
  61. var
  62.   mask1,mask2:byte;
  63.   offset1,offset2:word;
  64. begin
  65.   if (y<0) or (y>199) then exit;
  66.   if x1<0 then x1:=0;
  67.   if x1>319 then x1:=319;
  68.   if x2<0 then x2:=0;
  69.   if x2>319 then x2:=319;
  70.   mask1:=($F shl (x1 and 3));
  71.   mask2:=not ($FF shl ((x2 and 3)+1));
  72.   offset1:=x1 shr 2+y*$50;
  73.   offset2:=x2 shr 2+y*$50;
  74.   if offset1=offset2 then
  75.     mask1:=mask1 AND mask2
  76.   else
  77.     begin
  78.       portw[$3c4]:=$0002 or (mask2 shl 8);
  79.       mem[segment_adr[page]:offset2]:=color;
  80.       if offset2-offset1>1 then
  81.         begin
  82.           portw[$3C4]:=$0F02;
  83.           fillchar(mem[segment_adr[page]:offset1+1],offset2-offset1-1,color);
  84.         end;
  85.     end;
  86.   portw[$3c4]:=$0002 or (mask1 shl 8);
  87.   mem[segment_adr[page]:offset1]:=color;
  88. end;
  89.  
  90. Procedure ClearScreen (page:byte);
  91. begin
  92.   while (port[$3DA] and 8)<>8 do;
  93.   port[$3C4]:=2;
  94.   port[$3C5]:=$0F;
  95.   fillchar(mem[segment_adr[page]:$0000],$50*200,0);
  96. end;
  97.  
  98. Procedure CopyPage(page1,page2:byte);
  99. var
  100.   oldport:byte;
  101. begin
  102.   port[$3CE]:=5;
  103.   oldport:=port[$3Cf];
  104.   port[$3CE]:=5;
  105.   port[$3CF]:=oldport and $FC or 1;
  106.   move(mem[segment_adr[page1]:0],mem[segment_adr[page2]:0],$50*200);
  107.   port[$3CE]:=5;
  108.   port[$3CF]:=oldport;
  109. end;
  110.  
  111. end.